<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class User extends Controller
{
    public function index(){
        if (request()->isPost()){
            if (input('param.user_name')){
                $users=db('user')->where('user_status',1)->where('user_name',input('param.user_name'))->select();
            }elseif (input('param.user_phone')){
                $users=db('user')->where('user_status',1)->where('user_phone',input('param.user_phone'))->select();
            }else{
                $users=db('user')->where('user_status',1)->order('user_ctime','desc')->select();
            }
        }else{
            $users=db('user')->where('user_status',1)->order('user_ctime','desc')->select();
        }
        $this->assign('users',$users);
        return $this->fetch();
    }
    public function peisong(){
        if (request()->isPost()){
            if (input('param.user_name')){
                $users=db('user')->where('user_status',2)->where('user_name',input('param.user_name'))->select();
            }elseif (input('param.user_phone')){
                $users=db('user')->where('user_status',2)->where('user_phone',input('param.user_phone'))->select();
            }else{
                $users=db('user')->where('user_status',2)->order('user_ctime','desc')->select();
            }
        }else{
            $users=db('user')->where('user_status',2)->order('user_ctime','desc')->select();
        }
        $this->assign('users',$users);
        return $this->fetch();
    }
    public function sq(){
        $sqs=Db::table('lg_sq')
            ->alias('a')
            ->join('lg_user b ','b.user_id= a.sq_user_id')
            ->select();
        $this->assign('sqs',$sqs);
       return $this->fetch();
    }
    public function agreeSq(){
        $sqId=input('param.sq_id');
        $sqUser=Db::table('lg_sq')
            ->alias('a')
            ->join('lg_user b ','b.user_id= a.sq_user_id')
            ->where('a.sq_id',$sqId)
            ->find();
        $upSq=\db('sq')->where('sq_id',$sqId)->update(['sq_status'=>1]);
        if($upSq){
            $res=\db('user')->where('user_id',$sqUser['user_id'])->update(['user_status'=>2]);
            if($res){
                return json(['status'=>1,'msg'=>'审核通过成功']);
            }else{
                return json(['status'=>0,'msg'=>'审核失败']);
            }
        }else{
            return json(['status'=>0,'msg'=>'更新订单失败']);
        }
    }
    public function disagreeSq(){
        $sqId=input('param.sq_id');
        $res=\db('sq')->where('sq_id',$sqId)->update(['sq_status'=>2]);
        if($res){
            return json(['status'=>1,'msg'=>'审核成功']);
        }else{
            return json(['status'=>0,'msg'=>'审核失败']);
            }

    }
}
